//
//  WatermarkCell.swift
//  WatermarkCamera
//
//  Created by 赵新 on 5/7/2024.
//

import UIKit
import Kingfisher

// MARK: - [WatermarkCell]

class WatermarkCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        createUI()
    }

    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    lazy var selectMaskView: UIView = {
        let view = UIView()
        view.backgroundColor = .black.axc.alpha(0.7)
        view.layer.cornerRadius = 5
        view.layer.masksToBounds = true
        return view
    }()

    lazy var imageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()

    lazy var headlineLabel: UILabel = {
        let label = UILabel()
        label.adjustsFontSizeToFitWidth = true
        return label
    }()

    func createUI() {
        contentView.layer.cornerRadius = 5
        contentView.layer.masksToBounds = true
        contentView.layer.borderColor = "5290FD".axc.cgColor

        addSubview(imageView)
        imageView.addSubview(selectMaskView)
        headlineLabel.textColor = "323233".axc.uiColor
        headlineLabel.font = 14.axc.uiFont
        headlineLabel.textAlignment = .center
        addSubview(headlineLabel)

        imageView.snp.makeConstraints { make in
            make.top.left.equalTo(6)
            make.right.equalTo(-6)
            make.bottom.equalTo(-40)
        }

        selectMaskView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }

        headlineLabel.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(imageView.snp.bottom)
        }
    }

    func configModel(_ model: WatermarkDetailModel, isSelect: Bool) {
//        imageView.kf.setImage(with: model.templateImg.axc.url, placeholder: "wm_loading".axc.uiImage)
        imageView.image = model.imageName.axc.uiImage
        headlineLabel.text = model.name

        selectMaskView.isHidden = true
        if isSelect {
            selectMaskView.isHidden = false
            contentView.layer.borderWidth = 2
        } else {
            selectMaskView.isHidden = true
            contentView.layer.borderWidth = 0
        }
    }
}
